//
//  RNServiceDetailViewController.m
//  app
//
//  Created by 王宇宙 on 2017/12/25.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "RNServiceDetailViewController.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

@interface RNServiceDetailViewController ()

@end

@implementation RNServiceDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"服务详情";
    [self initRNView];
}

//- (void)viewWillAppear:(BOOL)animated {
//  [super viewWillAppear:animated];
//  [self.navigationController setNavigationBarHidden:NO animated:YES];
//}
//- (void)viewWillDisappear:(BOOL)animated {
//  [super viewWillDisappear:animated];
//  [self.navigationController setNavigationBarHidden:YES animated:YES];
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma MARK
- (void)initRNView {
  
  NSURL *jsCodeLocation;
#ifdef DEBUG
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"ServiceDetail"
                                               initialProperties:[self getProperties]
                                                   launchOptions:nil];
  
  rootView.frame = self.view.bounds;
  [self.view addSubview:rootView];
  
}

#pragma MARK Util
- (NSDictionary*)getProperties {
  NSString *tempString = [_linkUrl componentsSeparatedByString:@"desc/"].lastObject;
  NSArray *tempArray = [tempString componentsSeparatedByString:@","];
  NSString *yxId = tempArray[0];
  NSString *serviceId = tempArray[1];
  return @{@"yxId": yxId,
           @"serviceId": serviceId};;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
